package  com.pcbly.web.business.publicinfo;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.publicinfo.ArticleDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.publicinfo.ArticleBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class ArticleServiceImp extends BaseServiceImp<ArticleBean> implements ArticleService {
	 public ArticleServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private ArticleDao articleDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setArticleDao(ArticleDao articleDao) {
		this.articleDao = articleDao;
	}
	
	@Override
	public ArticleBean getArticleBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return articleDao.get(ArticleBean.class,id);
	}
	
	@Override
	public void removeArticleBeanById(String id) throws Exception{
		articleDao.removeArticleBeanById(id);
	}
	
	@Override
	public void removeArticleBeanByIds(String ids) throws Exception{
		articleDao.removeArticleBeanByIds(ids);
	}
	
	
	@Override
	public ArticleBean saveArticleBean(ArticleBean publicinfo) throws Exception{
		return articleDao.saveArticleBean(publicinfo);
	}
	
	@Override
	public ArticleBean updateArticleBean(ArticleBean publicinfo) throws Exception{
		articleDao.saveObject( publicinfo);
		return publicinfo;
	}
	public Page<ArticleBean>  findArticleBeanByCond(ArticleBean bean,
			Page<ArticleBean> page, String orderByName, boolean asc)
			throws Exception{
		return articleDao.findArticleBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findArticleBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findArticleBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = articleDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findArticleBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = articleDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveArticleBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		articleDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasArticleBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return articleDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
